﻿using DailyApp.WPF.Common;
using DailyApp.WPF.DTOs;
using DailyApp.WPF.Service;
using MaterialDesignThemes.Wpf;
using Prism.Commands;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace DailyApp.WPF.ViewModels.Dailogs
{
    /// <summary>
    /// 添加待办事项视图模型
    /// </summary>
    internal class AddWaitUCViewModel : IDialogHostAware//IDialogAware//弹框必须继承这个
    {
        //public string Title =>"添加待办事项";

        //public event Action<IDialogResult> RequestClose;
        ////能关闭吗
        //public bool CanCloseDialog()
        //{
        //    return true;
        //}
        ////关闭对话框时
        //public void OnDialogClosed()
        //{
        //}
        ////打开对话框时
        //public void OnDialogOpened(IDialogParameters parameters)
        //{
        //}

        /// <summary>
        /// 确定命令
        /// </summary>
        public DelegateCommand SaveCommand { get; set; }
        /// <summary>
        /// 取消命令
        /// </summary>
        public DelegateCommand CancelCommand { get; set; }
        /// <summary>
        /// 打开过程执行
        /// </summary>
        /// <param name="parameters"></param>
        public void OnDialogOpening(IDialogParameters parameters)
        {

        }

        /// <summary>
        /// 构造函数
        /// </summary>
        public AddWaitUCViewModel()
        {
            SaveCommand = new DelegateCommand(Save);
            CancelCommand = new DelegateCommand(Cancel);

        }

        /// <summary>
        /// 确定方法
        /// </summary>
        private void Save()
        {
            if (string.IsNullOrEmpty(WaitInfoDTO.Title) || string.IsNullOrEmpty(WaitInfoDTO.Content))
            {
                MessageBox.Show("待办事项信息不全");
                return;
            }
            if (DialogHost.IsDialogOpen(DailogHostName))//IsDialogOpen用于检查某个对话框是否打开
            {
                WaitInfoDTO.AccountId = UserInfoService.ACCOUNT_ID;
                DialogParameters paras = new DialogParameters();
                paras.Add("AddWaitInfo", WaitInfoDTO);
                DialogHost.Close(DailogHostName, new DialogResult(ButtonResult.OK, paras));
            }
        }
        /// <summary>
        /// 取消方法
        /// </summary>
        private void Cancel()
        {
            if (DialogHost.IsDialogOpen(DailogHostName))
            {
                DialogHost.Close(DailogHostName,new DialogResult(ButtonResult.No));//不给Ok就行,会被认为正常返回的 
            }
        }

        /// <summary>
        /// 待办事项的信息  绑定
        /// </summary>
        public WaitInfoDTO WaitInfoDTO { get; set; } = new WaitInfoDTO();//防止空引用出问题

        /// <summary>
        /// 对话框主机唯一标识值
        /// </summary>
        private const string DailogHostName = "RootDialog";
    }
}
